package com.tangchao.client.sdh.view
{
	import com.tangchao.client.sdh.definition.DFSuoFangDaXiao;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;

	public class SuoFangDaXiao extends MovieClip
	{
		private var _nowDaXiao:int=DFSuoFangDaXiao.ZHONG;
		private var _lastDaXiao:int=DFSuoFangDaXiao.ZHONG;
		private var _suoFangBtn:SimpleButton;
		private var _yuanBtn:SimpleButton;
		private var _zhongBtn:SimpleButton;
		private var _jinBtn:SimpleButton;
		private var _openState:Boolean=false;
		
		private var _parentUI:SanDaHaPanel;
		
		public function SuoFangDaXiao()
		{
			init();
		}
		
		public function setParentUI(ui:SanDaHaPanel):void
		{
			_parentUI = ui;
		}
		
		private function init()
		{
			_suoFangBtn=getChildByName("btSuoFangDaXiao") as SimpleButton;
			_yuanBtn=getChildByName("btYuan") as SimpleButton;
			_zhongBtn=getChildByName("btZhong") as SimpleButton;
			_jinBtn=getChildByName("btJin") as SimpleButton;
			
			changeOpenState();
			
			_suoFangBtn.addEventListener(MouseEvent.CLICK,onSuoFangClick);
			_yuanBtn.addEventListener(MouseEvent.CLICK,onYuanClick);
			_zhongBtn.addEventListener(MouseEvent.CLICK,onZhongClick);
			_jinBtn.addEventListener(MouseEvent.CLICK,onJinClick);
		}
		
		private function onSuoFangClick(e:MouseEvent)
		{
			_openState=!_openState;
			changeOpenState();
		}
		
		private function changeOpenState()
		{
			_yuanBtn.visible=_openState;
			_zhongBtn.visible=_openState;
			_jinBtn.visible=_openState;
		}
		
		private function onYuanClick(e:MouseEvent)
		{
			if(_parentUI)
			{
				_parentUI.onSetViewPos(DFSuoFangDaXiao.YUAN);
			}
		}
		
		private function onZhongClick(e:MouseEvent)
		{
			if(_parentUI)
			{
				_parentUI.onSetViewPos(DFSuoFangDaXiao.ZHONG);
			}
		}
		
		private function onJinClick(e:MouseEvent)
		{
			if(_parentUI)
			{
				_parentUI.onSetViewPos(DFSuoFangDaXiao.JIN);
			}
		}
		
		private function sendEvent()
		{
			
			if(_parentUI)
			{
				_parentUI.onSetViewPos(_nowDaXiao);
			}
			
//			if(_nowDaXiao!=_lastDaXiao)
//			{
//				var e:SuoFangEvent=new SuoFangEvent();
//				e.last=_lastDaXiao;
//				e.now=_nowDaXiao;
//				dispatchEvent(e);
//			}
		}
	}
}